package com.example.treeHole.controller;

import com.example.treeHole.result.Result;
import com.example.treeHole.service.ArticleMainService;
import com.example.treeHole.vo.ArticleMain;
import com.example.treeHole.vo.dto.ArticleMainDto;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/articleMain")
public class ArticleMainController {

    @Autowired
    private ArticleMainService articleMainService;


    /**
     * 分页查询文章
     * @param articleMainDto
     * @return
     */
    @GetMapping("/page")
    public Result<PageInfo<ArticleMain>> findPage(ArticleMainDto articleMainDto){
        PageInfo<ArticleMain> articleMainPageInfo = articleMainService.findPage(articleMainDto);

        return Result.success(articleMainPageInfo);
    }

    /**
     * 根据文章id查询
     * @param articleId
     * @return
     */
    @GetMapping("/findById/{articleId}")
    public Result<ArticleMain> findById(@PathVariable String articleId){
        ArticleMain articleMain = articleMainService.findById(articleId);
        return Result.success(articleMain);
    }

    /**
     * 查询置顶文章
     * @param articleId
     * @return
     */
    @GetMapping("/findTop")
    public Result<ArticleMain> findTop(@PathVariable String articleId){
        return null;
    }


    @PostMapping("/create")
    public Result<String> create(@RequestBody ArticleMain articleMain){
        String flag=articleMainService.create(articleMain);

        return Result.success(flag);
    }
}
